package com.example.game.module.mapper;

import com.example.game.module.entity.Game;
import com.example.game.module.dto.GameDTO;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface GameMapper {

    List<Game> findAll(@Param("offset") int offset, @Param("pageSize") int pageSize,@Param("keyword")String keyword,@Param("ids")String ids);

    //根据categoryId查询
    @Select("select * from game where category_id = #{categoryId} ")
    List<Game> findByCategoryId(@Param("categoryId") Long categoryId);

    @Select("SELECT COUNT(*) FROM game WHERE is_deleted = 0")
    Integer getTotalRecode();

    @Select("SELECT * FROM game WHERE id = #{gameId} ")
    Game getById(@Param("gameId") Long gameId);

    @Select("SELECT * FROM game WHERE id = #{gameId} ")
    Game extractById(Long gameId);

    //根据gameId连表查询
    GameDTO getGameDTOById(Long gameId);
    int insert(Game game);

    int update(Game game);

    //单个删除
    @Update("UPDATE game SET is_deleted = 1,update_time = #{updateTime} WHERE id = #{gameId}")
    int delete(@Param("gameId") Long gameId, @Param("updateTime") Integer updateTime);

    //批量删除
    @Update({"<script> " +
            "UPDATE game SET is_deleted = 1,update_time = #{updateTime} WHERE id IN" +
            "<foreach collection='gameIds' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script> "})
    int deleteByIds(@Param("gameIds") List<Long> gameIds, @Param("updateTime") Integer updateTime);


}
